from typing import *


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution:
    def increasingBST(self, root: TreeNode) -> TreeNode:

        r = TreeNode()
        c = r

        def f(node):
            if node is None:
                return
            f(node.left)
            nonlocal c
            c.right = TreeNode(node.val)
            c = c.right
            f(node.right)

        f(root)

        return r.right
